//
//  XMGNavgationController.m
//  百思不得姐
//
//  Created by 杨庆 on 2016/12/30.
//  Copyright © 2016年 杨庆. All rights reserved.
//

#import "XMGNavgationController.h"

@interface XMGNavgationController ()

@end

@implementation XMGNavgationController
+(void)initialize{
	//设置 navbar 的背景图片
	UINavigationBar*bar=[UINavigationBar appearance];
	[bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
	
}
- (void)viewDidLoad {
    [super viewDidLoad];

	
}

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
	//如果不判断,在"我"一栏里面是没有 leftButtonItem 按钮的,这样会导致在"我"一栏里面多一个返回按钮

	if (self.childViewControllers.count>0) {
		
		UIButton*btn=[UIButton buttonWithType:UIButtonTypeCustom];
		[btn setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
		[btn setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
		btn.size =CGSizeMake(100, 30);
		
		[btn setTitle:@"返回" forState: UIControlStateNormal];
		btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
		btn.contentEdgeInsets=UIEdgeInsetsMake(0, -10, 0, 0);
		[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
		[btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
		[btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
		viewController.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:btn];
		
		viewController.hidesBottomBarWhenPushed=YES;
	}
	//先进行判断,后执行 push 的好处: 在不需要设置的返回按钮的地方,就少了push 操作,节省内存
	[super pushViewController:viewController animated:animated];

}

-(void)back{
	[self popViewControllerAnimated:YES];
}

@end
